package dk.degofedal.scala.math

import dk.degofedal.scala.math.numerical.NewtonRaphson
import dk.degofedal.scala.math.numerical.Bisection
import compat.Platform._

object Tester {
	
  def pi = Math.Pi
	  
  def main(args : Array[String]) : Unit = {
	  
	  
	  //val fib = new Fibonacci();
	  
	  //val start = currentTime
	  //println("Fib :"+fib.fib_recursive(40));
	  //val t1 = currentTime
	  //println("Fib :"+fib.fib_linear(40, List(1,0)));
	  //val t2 = currentTime
	  
	  //println("Recursive : "+(t1-start))
	  //println("Linear    : "+(t2-t1))
	   
	  
	  /*val a = new Phasor(220, 0 , 50);
	   
	   println("Phasor A "+a);
	     
	  val b = a * 0.5
	  
	  println("Phasor B "+b);
	   
	  println("A + B = " + (a + b));*/
	   
	  /*val l1 = new Phasor(220, 0, 50)
	  val l2 = l1 * (1, 2*pi/3)
	  val l3 = l1 * (1, 4*pi/3)
	  
	  println("L1 "+l1);
	  println("L2 "+l2);
	  println("L3 "+l3);
	   
	  println("L1+L2+L3 "+(l1 + l2 + l3))*/
	  
	  /*val f = new Fraction(2 ,3)
	  println(f)
	  
	  val g = f * 'pi
	  println(g)
	   
	  val h = g / 'pi
	  println(h)*/
	   
	  val factorize : List[Int] = new Factorize(256).f
	  //println(factorize )
	  
	  println(factorize.foldLeft(1)(_*_))
	  
	  //val bisec = new Bisection
	  //println (bisec.solve(0,2)((x) => 2*x*x - 3*x - 1))
	  
	  val newton = new NewtonRaphson
	  //println (newton.solve(0)((x) => x*x - 612))
	  
	  def sqrt(x: Double, method: NewtonRaphson) = {
	 	  println (method.solve(x, (a) => a*a - x))
	  }
	   
	  def sqrt_d(x: Double, method: NewtonRaphson) = {
	 	  println (method.solve(x, (a) => a*a - x, (a) => 2*a))
	  } 
	   
	  sqrt(61253179, newton)  
	  
	  sqrt_d(61253179, newton)
  }
}
